define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'toastr'], function ($, undefined, Backend, Table, Form, Toastr) {

    var Controller = {
        index: function () {
            function debounce(handle, delay) {
                let time = null;
                return function () {
                    let self = this,
                        arg  = arguments;
                    clearTimeout(time);
                    time = setTimeout(function () {
                        handle.apply(self, arg);
                    }, delay)
                }
            }

            var userIndex = new Vue({
                el: "#trackingHealthIndex",
                data() {
                    return {
                        chooseType   : 0,
                        data         : [],
                        offset       : 0,
                        limit        : 10,
                        totalPage    : 0,
                        currentPage  : 1,
                        healthService: [],//平安健康服务列表
                        created_at   : '',//查询时间
                        summary      : [],
                    }
                },
                created() {
                    this.healthService = Config.health_service || [];
                    this.getData();
                },
                methods: {
                    getData() {
                        let that = this;
                        Fast.api.ajax({
                            url    : 'health/tracking/health/index',
                            loading: true,
                            type   : 'GET',
                            data   : {
                                created_at: this.created_at,
                            },
                        }, function (ret, res) {
                            that.data = res.data.rows;
                            return false;
                        })
                    },
                    isChoose() {
                    },
                    operation(type, id) {
                        let that = this;
                        switch (type) {
                            case 'filter':
                                this.getData()
                                break;
                            case 'clear':
                                this.created_at = '';
                                break;
                        }
                    },
                    tableRowClassName({rowIndex}) {
                        if (rowIndex % 2 == 1) {
                            return 'bg-color';
                        }
                        return '';
                    },
                    tableCellClassName({
                                           columnIndex
                                       }) {
                        if (columnIndex == 2 || columnIndex == 9) {
                            return 'cell-left';
                        }
                        return '';
                    },
                    debounceFilter: debounce(function () {
                        this.getData()
                    }, 1000),
                },
                watch  : {},
            })
        },
        add  : function () {
        },
        api  : {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },

    };
    return Controller;
});
